/**
 * 图表自定义指令和服务
 * @author Peter
 * @Date 2016-5-25
 */
angular.module('mamApp').directive('chart', [function(){
  return {
    restrict: 'A',
    replace: false,
    scope: {
      chart: '=',
      init:'@'
    },
    link: function (scope, element, attrs) {
      var chart = echarts.init($(element).get(0));
      var chartWidth=$(element).width();

      scope.$watch('chart',function (newValue,oldValue) {
        if(newValue){
          chart.setOption(newValue)
        }
      },true)
      scope.$parent.$watch('close',function (newValue,oldValue) {

        if(newValue){
          $(element).css({width: chartWidth+200 + "px"})
          chart.resize()

        }else{
          $(element).css({width: chartWidth + "px"})
          chart.resize()
        }

      })
    }
  };
}]);
